import { io, type Socket } from "socket.io-client";

export const state = reactive<{
  connected: boolean;
  fooEvents: Array<any>;
  barEvents: Array<any>;
}>({
  connected: false,
  fooEvents: [],
  barEvents: [],
});

const URL = "ws://localhost:3000";
export const socket: Socket = io(URL);

socket.on("connect", () => {
  state.connected = true;
});

socket.on("disconnect", () => {
  state.connected = false;
});
socket.on("foo", (...args: any[]) => {
  state.fooEvents.push(args);
});
socket.on("bar", (...args: any[]) => {
  state.barEvents.push(args);
});
